package cn.skycity.common.service.impl;

import cn.skycity.common.mapper.SysDictDataMapper;
import cn.skycity.common.service.ISysDictDataService;
import cn.skycity.framework.core.service.DictService;
import cn.skycity.framework.core.utils.StreamUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skycity.framework.uaa.pojo.entity.SysDictData;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YingBo.Dai
 * @since 2024-12-13
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements DictService,ISysDictDataService {

    @Override
    public String getDictLabel(String dictType, String dictValue, String separator) {
        SysDictData sysDictItem = baseMapper.selectOne(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType).eq(SysDictData::getDictValue, dictValue));
        return Objects.requireNonNull(sysDictItem).getDictLabel();
    }

    @Override
    public String getDictValue(String dictType, String dictLabel, String separator) {
        SysDictData sysDictItem = baseMapper.selectOne(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType).eq(SysDictData::getDictLabel, dictLabel));
        return Objects.requireNonNull(sysDictItem).getDictValue();
    }

    @Override
    public Map<String, String> getAllDictByDictType(String dictType) {
        List<SysDictData> dictItemList = baseMapper.selectList(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType));
        return StreamUtils.toMap(dictItemList, SysDictData::getDictValue, SysDictData::getDictLabel);
    }
}
